package com.css.fxfzypg.modules.baseData.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.constants.YNEnum;
import com.css.fxfzypg.modules.baseData.entity.DisasterScene;
import com.css.fxfzypg.modules.baseData.entity.Elevation;
import com.css.fxfzypg.modules.baseData.queryParams.DisasterSceneQueryParams;
import com.css.fxfzypg.modules.baseData.queryParams.ElevationQueryParams;
import com.css.fxfzypg.modules.baseData.repository.DisasterSceneRepository;
import com.css.fxfzypg.modules.baseData.repository.ElevationRepository;
import com.css.fxfzypg.modules.baseData.service.DisasterSceneService;
import com.css.fxfzypg.modules.baseData.service.ElevationService;
import com.css.fxfzypg.modules.baseData.vo.ElevationVO;
import com.css.fxfzypg.util.FileUtil;
import com.css.fxfzypg.util.PlatformDateUtils;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Service
public class DisasterSceneServiceImpl implements DisasterSceneService {

    @Resource
    DisasterSceneRepository disasterSceneRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public DisasterScene updateDisasterScene(DisasterScene disasterScene) {

        disasterScene.setDsUpdatetime(PlatformDateUtils.getCurrentTimestamp());
       disasterSceneRepository.updateDisasterScene(disasterScene);

       return null;
    }

    @Override
    @Transactional
    public DisasterScene saveDisasterScene(DisasterScene disasterScene) {
        disasterScene.setDsId(UUIDGenerator.getUUID());
        disasterScene.setDsStatus(YNEnum.Y.toString());
        disasterScene.setDsCreatetime(PlatformDateUtils.getCurrentTimestamp());
        return disasterSceneRepository.saveDisasterScene(disasterScene);
    }

    @Override
    public Map<String,Object> getAllDisasterScene(DisasterSceneQueryParams queryParams) {
        return disasterSceneRepository.getAllDisasterSceneParams(queryParams);
    }

    @Override
    public DisasterScene getDisasterSceneById(String id) {
        DisasterScene disasterScene = disasterSceneRepository.getDisasterSceneById(id);
        return disasterScene;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteDisasterScenes(List<String> ids) {
        Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        disasterSceneRepository.deleteDisasterScenesById(ids,timestamp);
    }

//    @Override
//    public List<DisasterScene> getAll() {
//
//        return disasterSceneRepository.getAll();
//    }

    //   @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void importExcel(MultipartFile file) throws IOException {
//        List<DisasterScene> disasterScenes = FileUtil.importExcel(file, DisasterScene.class);
//        for(int i = 0 ; i<disasterScenes.size();i++){
//            disasterScenes.get(i).setDsId(UUIDGenerator.getUUID());
//            disasterScenes.get(i).setDsStatus(YNEnum.Y.toString());
//
//        }
//        disasterSceneRepository.importExcel(disasterScenes);
//    }
}
